//
//  MainViewController.h
//  OffscreenRendererTest
//
//  Created by Nicolò Tosi on 4/16/10.
//  Copyright 2010 MobFarm S.r.l. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MFDocumentViewControllerDelegate.h"
#import "MFDocumentOverlayDataSource.h"
#import "FPKOverlayViewDataSource.h"
#import "FPKThumbnailDataStore.h"
#import "FPKSharedSettings.h"
#import "FPKDestination.h"

@class MFDeferredContentLayerWrapper;
@class MFDocumentManager;
@class MFDocumentViewController;

@protocol FPKThumbnailView

@property (nonatomic, copy) NSString * title;
@property (nonatomic, strong) UIImage * image;

@end

extern NSString * const FPKConfigurationDictionaryConfigKey;
extern NSString * const FPKConfigurationDictionaryPageKey;
extern NSString * const FPKConfigurationDictionaryOrientationKey;
extern NSString * const FPKConfigurationDictionaryModeKey;
extern NSString * const FPKConfigurationDictionaryPaddingKey;
extern NSString * const FPKConfigurationDictionaryEdgeFlipKey;
extern NSString * const FPKConfigurationDictionaryAlternateEdgeFlipKey;

static const NSUInteger FPKEmbeddedAnnotationsVideo = 1;
static const NSUInteger FPKEmbeddedAnnotationsAudio = 2;
static const NSUInteger FPKEmbeddedAnnotationsWeb = 4;
static const NSUInteger FPKEmbeddedAnnotationsAll = FPKEmbeddedAnnotationsAudio|FPKEmbeddedAnnotationsVideo|FPKEmbeddedAnnotationsWeb;

@interface MFDocumentViewController : UIViewController <UIScrollViewDelegate>


@property (nonatomic, readonly) NSPointerArray * delegates;


@property (nonatomic,readwrite) NSUInteger supportedOrientations;

@property (nonatomic, readwrite) NSUInteger supportedEmbeddedAnnotations;

@property (nonatomic,strong)id<FPKThumbnailDataStore> thumbnailDataStore;

@property (nonatomic, copy) NSDictionary * configurationDictionary;

@property (weak) id<MFDocumentViewControllerDelegate> documentDelegate;

-(void)addDocumentDelegate:(NSObject<MFDocumentViewControllerDelegate> *)delegate;



-(void)removeDocumentDelegate:(NSObject<MFDocumentViewControllerDelegate> *)delegate;

@property (nonatomic,readwrite) FPKSupportedOrientation supportedOrientation;

@property (nonatomic, readonly) MFDocumentManager * document;

@property (nonatomic,readwrite,getter = isDirectionLockEnabled) BOOL directionalLockEnabled;

@property (readwrite) BOOL useTiledOverlayView;

@property (nonatomic,readwrite) BOOL showHorizontalScroller;

@property (nonatomic,readwrite) BOOL showShadow;

@property (nonatomic,readwrite) CGFloat padding;

-(void)addOverlayDataSource:(id<MFDocumentOverlayDataSource>)ovds;

-(void)removeOverlayDataSource:(id<MFDocumentOverlayDataSource>)ods;

@property (nonatomic,readwrite) BOOL fpkAnnotationsEnabled;

-(id<FPKOverlayViewDataSource>)overlayViewDataSourceWithName:(NSString *)name;

-(void)addOverlayViewDataSource:(id<FPKOverlayViewDataSource>)ovds name:(NSString *)name;


-(NSString *)addOverlayViewDataSource:(id<FPKOverlayViewDataSource>)ovds;

-(void)removeOverlayViewDataSource:(id<FPKOverlayViewDataSource>)ovds;

-(id<FPKOverlayViewDataSource>)removeOverlayViewDataSourceWithName:(NSString *)name;

-(void)reloadOverlay;

-(float)zoomLevelForAnnotationRect:(CGRect)rect ofPage:(NSUInteger)page;

-(float)zoomScale;

-(CGPoint)zoomOffset;

-(NSUInteger)leftPage;

/**
 This method will return the page number of the right page displayed. If the mode
 is single, right page number is invalid.
 */
-(NSUInteger)rightPage;

/**
 Document identifier, to allow discriminate between different documents.
 */
@property (nonatomic, copy) NSString * documentId;

/**
 在文档的起始页。它只有在初始化和视图显示在屏幕上之后才有效。你需要在viewController的init之后设置它。
 默认是1.
 */
@property (nonatomic,readwrite) NSUInteger startingPage;

/**
 当用户触摸屏幕的边缘时启用页面翻转
 */
@property (assign,readwrite,getter=isPageFlipOnEdgeTouchEnabled) BOOL pageFlipOnEdgeTouchEnabled;

/**
 设置并获取与页面翻转有关的屏幕的百分比。默认值是0.1，这意味着任何一方屏幕的宽度的10%都会收到这样的事件。值在0.0到0.5之间，以防止重叠。
 */
@property (nonatomic,readwrite) CGFloat edgeFlipWidth;

/**
 当用户双击屏幕时启用放大功能。
 */
@property (nonatomic,readwrite,getter=isZoomInOnDoubleTapEnabled) BOOL zoomInOnDoubleTapEnabled;

/**
 启用文档交互。
 */
@property (nonatomic,readwrite,getter=isDocumentInteractionEnabled) BOOL documentInteractionEnabled;

/**
 在文档上启用或禁用覆盖项显示。
 默认是禁用的.
 */
@property (nonatomic,readwrite,getter = isOverlayEnabled) BOOL overlayEnabled;

/**
 启用或强制“遗留模式”，或让应用程序选择启用或不依赖于设备。默认是禁用的.
 */
@property (nonatomic,readwrite,getter = isLegacyModeEnabled) BOOL legacyModeEnabled;

/**
 这是pdf将放大的默认最大放大倍数.
 */
@property (nonatomic,readwrite) float defaultMaxZoomScale;

/**
 Call this method to start working with the pdf.
 @param aDocumentManager The MFDocumentManager to use.
 */
-(id)initWithDocumentManager:(MFDocumentManager *)aDocumentManager;

/**
 Call this method to start working with the pdf.
 @param aDocumentManager The MFDocumentManager to use.
 @param count Max amount of concurrent operations. Pass 0 to set it to an automatic value.
 */
-(id)initWithDocumentManager:(MFDocumentManager *)aDocumentManager count:(NSUInteger)count;

/**
 This metod enable or disable the automatic mode switching upon rotation. If 
 enabled, the page mode will be automatically changed to single page in portrait 
 and side-by-side (double) on landscape. Setting the mode manually will disable 
 the automode.
 */
-(BOOL)automodeOnRotation;

/**
 Returns whether automode is enabled or not.
 */
-(void)setAutomodeOnRotation:(BOOL)automode;

/**
 Set how the pages are presented to the user. MFDocumentModeSingle present a 
 single page to the user, centered on the screen. MFDocumentModeDouble present 
 two pages side-by-side, as they would appear on a magazine or a books. This 
 will allow to preserve content split between the pages, for example a large 
 background image.
 */
-(void)setMode:(MFDocumentMode)newMode;


/**
 Set the mode to which the document will automatically switch to upon rotation. 
 Pass MFDocumentAutoModeX values and not MFDocumentModeX values, since it is not
 guaranteed to be the same.
 */
-(void)setAutoMode:(MFDocumentAutoMode)newAutoMode;

/**
 Returns the current mode used to display the document.
 */
-(MFDocumentMode)mode;

/**
 这个metod将设置文档的当前页面并跳转到指定的页面。当前页面用于确定书签位置。在并行(double)模式下，它通常是两个页面的最左页.
 */
-(void)setPage:(NSUInteger)page;

/**
 *该方法将文档的当前页面跳转到指定的页面，而试图放大在指定的矩形。通过ZoomLevel让应用尝试计算出适当的缩放以适合矩形屏幕。
 */
-(void)setPage:(NSUInteger)page withZoomOfLevel:(float)zoomLevel onRect:(CGRect)rect;

/**
 * Will attemp to reach the destination.
 * It will return YES if the destination has been found on the current document,
 * otherwise NO.
 */
-(BOOL)setDestination:(id<FPKDestination>)destination;

/**
 Returns the current page of the document.
 */
-(NSUInteger)page;

/**
 This method set the lead used to show the pages in side-by-side (double) mode. 
 With MFDocumentLeadLeft, the cover will appear on the left side in side-by-side
 mode, whereas with MFDocumentLeadRight will appear on the right side. Use this 
 method to keep pairing between pages for books and magazines. Single page mode 
 is not affected by this setting.
 */
-(void)setLead:(MFDocumentLead)newLead;

/**
 返回在显示文档时使用的当前引导.
 */
-(MFDocumentLead)lead;

/**
 This method is used to set the page reading direction: left to right or right 
 to left.
*/
-(void)setDirection:(MFDocumentDirection)newDirection;

/**
 返回文档使用的当前方向
 */
-(MFDocumentDirection)direction;

/**
 该方法将打开或关闭自动缩放功能。如果打开，当前的缩放级别将被保存在页面之间，否则将在页面更改上保持100%.
 */
-(void)setAutozoomOnPageChange:(BOOL)autozoom;

/**
 返回自动缩放功能是否启用.
 */
-(BOOL)autozoomOnPageChange;

/**
 动画过渡到下一页
 */
-(void)moveToNextPage;

/**
     This method will begin an animated transition to the previous page, if
     available.
 */
-(void)moveToPreviousPage;

/**
 Call this method rightly after dismissing this MFDocumentViewController 
 instance. It will release all the resources and stop the background threads. 
 Once this method has been called, the MFDocumentViewController instance cannot 
 be considered valid anymore and should be released.
 */
-(void)cleanUp;

/**
 Convert a point from MFDocumentViewController's view space to page space.
 */
-(CGPoint)convertPoint:(CGPoint)point fromViewtoPage:(NSUInteger)page;

/**
 Convert a point from page space to MFDocumentViewController's view space.
 */
-(CGPoint)convertPoint:(CGPoint)point toViewFromPage:(NSUInteger)page;

/**
 Convert a rect from MFDocumentViewController's view space to page space.
 */
-(CGRect)convertRect:(CGRect)rect fromViewToPage:(NSUInteger)page;

/**
 Convert a rect from page space to MFDocumentViewController's view space.
 */
-(CGRect)convertRect:(CGRect)rect toViewFromPage:(NSUInteger)page;

/**
 Convert a point from overlay space (the whole view that hold the both left and 
 right page, and that you can zoom in and scroll over) to page space.
 */
-(CGPoint)convertPoint:(CGPoint)point fromOverlayToPage:(NSUInteger)page;

/**
 Convert a point from page space to overlay space.
 */
-(CGPoint)convertPoint:(CGPoint)point toOverlayFromPage:(NSUInteger)page;

/**
 Convert a rect from overlay space to page space.
 */
-(CGRect)convertRect:(CGRect)rect fromOverlayToPage:(NSUInteger)page;

/**
 Convert a ract from page to overlay space.
 */
-(CGRect)convertRect:(CGRect)rect toOverlayFromPage:(NSUInteger)page;

/**
 Override in your subclass to toggle gesture recognizer on overlay views on and 
 off.
 */
-(BOOL)gesturesDisabled;

/**
 Set the paged scroll enabled or not. Useful to lock the user in the current 
 page during animations.
 */
-(void)setScrollEnabled:(BOOL)lock;

/**
 设置pdf页面最大缩放比例.
 */
-(void)setMaximumZoomScale:(NSNumber *)scale;


/**
 Hide the bottom thumbnail scroll view.
 */
-(void)hideThumbnails;

/**
 Show the bottom thumbnail scroll view.
 */
-(void)showThumbnails;

/**
 Set the max number of preview images to use at any time. Call this before 
 presenting the MFDocumentViewController subclass. Default is 4, sweet spot is
 3-4 and you should not exceed this number unless your target device are iPhone4 
 iPad2 or newer devices and/or your PDF are scarce of images.
 */
@property (nonatomic,readwrite) NSUInteger previewsCount;

/**
 Access the inner paged scroll view.
 */
@property (strong, readonly) UIScrollView * pagedScrollView;

/**
 * Height of the thumbnail in the scrollview. Default is 80.
 */
@property (nonatomic, readwrite) CGFloat thumbnailHeight;

/**
 * Background color of the thumbnailview.
 */
@property (nonatomic, strong) UIColor * thumbnailBackgroundColor;

/**
 * Enabled or disable the page slider item in the toolbar.
 */
@property (nonatomic, readwrite, getter = isPageSliderEnabled) BOOL pageSliderEnabled;

/**
 * Enable or disable the thumbnail slider item in the toolbar. The page slider will
 * take the precedence over this one.
 */
@property (nonatomic, readwrite, getter = isThumbnailSliderEnabled) BOOL thumbnailSliderEnabled;

/**
 * Enable or disable background thumbnail rendering, even when the thumbnail slider is not visible.
 * Default is YES.
 */
@property (nonatomic, readwrite) BOOL backgroundThumbnailRenderingEnabled;

/**
 加密缓存图像的关键。如果左侧为nil默认值，则图像将不会被加密。请记住，现在，如果您更改了与某个文档相关的文档(您不太可能需要这样做)，您必须手动删除缩略图缓存。
 */
@property (copy, nonatomic) NSString * cacheEncryptionKey;

/**
 这条路径将被用来缓存缩略图图像。如果用户未定义，则该组件将根据文档首先生成一个，然后是共享的。
 */
@property (copy, atomic, readwrite) NSString * thumbnailsCachePath;

/**
 This path will be used to cache the page images. If left undefined by the
 user, the kit will generate one depending on the documentId first, then a
 shared one.
 */
@property (copy, atomic, readwrite) NSString * imagesCachePath;

/**
 Visited pages system.
 */

/**
 * This will move to the next visited page, if any.
 */
-(void)nextVisitedPage;

/**
 * This will go back to the previously visited page, if any.
 */
-(void)previousVisitedPage;

/**
 * Amount of forward visited pages. It will be greather than 0
 * only when the user as jumped back.
 */
-(NSInteger)nextVisitedPagesCount;

/**
 * Amount of previously visited pages. It is usually greather than 0,
 * unless the user has already jumped to the bottom of the stack.
 */
-(NSInteger)previousVisitedPagesCount;

/**
 * This will set the image cache scale to use. You can choose between 
 * FPKImageCacheStandard, FPKImageCacheTrueToPixels and FPKImageCacheAnamorphic.
 *
 * Default si FPKImageCacheTrueToPixels.
 */
-(void)setImageCacheScaling:(FPKImageCacheScale)scale;
-(FPKImageCacheScale)imageCacheScaling;

/**
 * This set if image cache will use JPEG or the default PNG compression.
 *
 * Default is YES (it will use JPEG).
 */
-(void)setUseJPEG:(BOOL)useJPEGOrNot;
-(BOOL)useJPEG;

/**
 * This set the compressione level for the JPEG image compression, if JPEG
 * image compression is used (greather the value lesser the compression). 
 * Level 0.75 is a good compromise between image quality, speed and size.
 *
 * Default is 0.75.
 */
-(void)setImageCacheCompression:(CGFloat)level;
-(CGFloat)imageCacheCompression;

/**
 * This will set if high detailed tiles will be shown at 1x zoom factor. You 
 * can choose between FPKForceTilesNever, FPKForceTilesAlways,
 * FPKForceTilesOverflowOnly.
 *
 * Default is FPKForceTilesOverflowOnly.
 */
-(void)setForceTiles:(FPKForceTiles)force;
-(FPKForceTiles)forceTiles;

/**
 * This wil set the oversize of the image cache. Image size will be calculated
 * taking screen size and page cropbox size into account to produce and image 
 * that will fit the screen. Oversize is a factor of how much the final image 
 * will be bigger than the optimal. Oversize of 0.05 will generate an image 
 * with roughly 10% more pixel than the screen (1.05 * 1.05 = 1.1).
 *
 * Default is 0.05.
 */

-(void)setImageCacheOversize:(CGFloat)oversize;
-(CGFloat)imageCacheOversize;

/**
 * This flag will force the controller to delete the cache at launch. The flag
 * will be reset to NO after clean up.
 */
@property (readwrite, nonatomic) BOOL cleanUpCacheAtLaunch;

/**
 * This will tell the controller to use the navigation controller's toolbar
 * instead of its own. Toolbar items will be replaced with document controller's
 * own items. Default is NO. Since navigation toolbar is usually 44 points high, 
 * it would be better to set pageSliderEnabled to YES and thumbnailSliderEnabled
 * to NO rather to try fit the thumbnails into the navigation toolbar.
 */
@property (readwrite, nonatomic) BOOL useNavigationControllerToolbar;

/**
 * Height of the toolbar. Set to force toolbar height, otherwise 44.0 will be
 * used if page slider is enabled, 88.0 if thumbnails are enabled. 
 * Default is -1.0.
 */
@property (readwrite, nonatomic) CGFloat thumbnailBarHeight;

/**
 * Toolbar. It will return nil if useNavigationToolbar has been set to YES.
 */
@property (strong, nonatomic) UIToolbar * toolbar;

/**
 * 当用户通过在滑块外部触摸来取消页面滑块移动时调用。如果你想要嵌入的pageSliderLabel来重新设置实际的页码，。
 * @param slider The slider.
 */
-(void)pageSliderCancel:(UISlider *)slider;

/**
 * Invoked when the slider slided. This is used to update the pageSliderLabel to
 * show the page that will be loaded when the slider is released. When you override
 * this method, remember to call super.
 * @param slider The slider.
 */
-(void)pageSliderSlided:(UISlider *)slider;

/**
 * Invoked when the user stop dragging the slider and release it by touching up 
 * inside the slider bounds. When you override this, call super if you want the 
 * current displayed page to be updated accordingly.
 * @param slider The slider.
 */
-(void)pageSliderStopped:(UISlider *)slider;

/**
 * Return the number of the page at the current view location.
 * @param location A location in the controller's view.
 * @return The number of the page at the location.
 */
-(NSUInteger)pageAtLocation:(CGPoint)location;

/**
 * Settings object.
 */
@property (nonatomic, strong) FPKSharedSettings * settings;

@end
